#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

typedef struct No{
    char data;
    struct No* next;
} noPilha;

noPilha* prim = NULL;
noPilha* ult = NULL;

int quant = 0;

char getFirst();
char getLast();
char getTopo();
bool isEmpty();
int getQuant();
void printStack();

bool push(char valor);
char popo();
void destroiPilha();

void dec2hex(int dec);
char dec2char(int dec); //converte 10 -> A; 11->B, etc.

int main(int argc, char** argv){
    int valor;
    cout << "Digite um valor: ";
    cin >> valor;
    dec2hex(valor);
    printStack();

    destroiPilha();

}

char getFirst(){
    if (!prim) return -1;
    else return prim->data;
}
//---

char getLast(){
    if (!ult) return -1;
    else return ult->data;
}
//---

char getTopo(){
    if(!prim) return -1;
    else return prim->data;
}
//---

bool isEmpty(){
    if(!prim) return true;
    else return false;
}
//---

int getQuant(){
    return quant;
}
//---

void printStack(){
    for(noPilha* node = prim; node != NULL; node = node->next){
        cout << node->data;
    }
    cout << endl;
}
//---

bool push(char valor){
    noPilha* novo = new noPilha;
    if(!prim) ult = novo;
    novo->data = valor;
    novo->next = prim;
    prim = novo;
    quant++;
    return true;
}

//---
char popo(){
    char valor = prim->data;
    noPilha* aux = prim;
    if(!(prim->next)) ult = NULL;
    prim = prim->next;
    if(aux) free(aux);
    quant--;
    return valor;
}
void destroiPilha(){
    noPilha* atual = prim;
    noPilha* apaga;
    while(atual){
        apaga = atual;
        atual = atual->next;
        free(apaga);
    }
}

void dec2hex(int dec){

    if(dec<10)
        push(dec2char(dec));
    else{
        while(dec >= 10){
            push(dec2char(dec%16));

            dec /= 16;
        }
        push(dec2char(dec));
    }


}
char dec2char(int dec){
    switch(dec){
        case 0: return '0'; break;
        case 1: return '1'; break;
        case 2: return '2'; break;
        case 3: return '3'; break;
        case 4: return '4'; break;
        case 5: return '5'; break;
        case 6: return '6'; break;
        case 7: return '7'; break;
        case 8: return '8'; break;
        case 9: return '9'; break;
        case 10: return 'A'; break;
        case 11: return 'B'; break;
        case 12: return 'C'; break;
        case 13: return 'D'; break;
        case 14: return 'E'; break;
        case 15: return 'F'; break;
    }

} //converte 10 -> A; 11->B, etc.


